# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=zfp
pkgver=1.0.0
pkgrel=2
pkgdesc="Compressed numerical arrays that support high-speed random access"
arch=(loong64 x86_64)
url="https://computing.llnl.gov/projects/floating-point-compression"
license=(BSD)
depends=(glibc gcc-libs)
makedepends=(cmake gcc-fortran cython python python-numpy)
source=(https://github.com/LLNL/zfp/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz
        zfp-fix-libm-check.patch::https://github.com/LLNL/zfp/commit/6d7d2424ed082eb41d696036b26831636650a614.patch)
sha256sums=('fe13b03141ee9b571692aed42ff76cf37c9dcda40f9a43a808870dca3558a57c'
            'fb90be8fd65448a209ea18e042e91d9207ebef63320da5cda9a2902309154e48')

prepare() {
  # https://github.com/LLNL/zfp/issues/169
  patch -d $pkgname-$pkgver -Np1 < zfp-fix-libm-check.patch
}

build() {
  cmake -B build -S ${pkgname}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_SKIP_RPATH=ON \
    -DBUILD_CFP=ON \
    -DBUILD_ZFPY=ON \
    -DBUILD_ZFORP=ON
  make -C build
}

check() {
  cd build
  LD_LIBRARY_PATH="$(pwd)"/lib/ ctest -v --output-on-failure
}

package() {
  make -C build DESTDIR="${pkgdir}" install
  install -D build/bin/zfp -t "${pkgdir}"/usr/bin
  install -Dm644 ${pkgname}-${pkgver}/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
